
import Vue from 'vue'
import VueRouter from 'vue-router'

// import Main from '../components/Main.vue'
const Main = () => import(/* webpackChunkName: "main" */ '../components/Main.vue')
// import Page from '../components/page/Page.vue'
const Page = () => import(/* webpackChunkName: "main" */ '../components/page/Page.vue')
// import Frontend from '../components/frontend/Frontend.vue'
const Posts = () => import(/* webpackChunkName: "posts" */ '../components/posts/Posts.vue')
// import Posts from '../components/posts/Posts.vue'

const Frontend = () => import(/* webpackChunkName: "fron" */ '../components/frontend/Frontend.vue')

Vue.use(VueRouter)

const routes = [{
  path: '/',
  component: Main,
  redirect: '/page',
  children: [
    {
      path: '/page',
      component: Page
    },
    {
      path: '/frontend',
      name: 'frontend',
      component: Frontend
    },
    {
      path: '/posts/:userId',
      name: 'posts',
      component: Posts
    }
  ]
},
{
  path: '/indexCard',
  redirect: '/'
}
]

// 路由挂载在vue中
const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    // 异步滚动操作
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({ x: 0, y: 1 })
      }, 0)
    })
  }
})

export default router
